home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / vsc92nov.zip / Boolean.c < prev    next >
C/C++ Source or Header  |  1992-11-02  |  2KB  |  94 lines

  1. /*
  2.  * Boolean.c -- Implementation of Scheme Booleans (and ())
  3.  *
  4.  * (C) m.b (Matthias Blume), Mar 1992, HUB/Ger
  5.  */
  6.  
  7. # ident "@(#)Boolean.c    (C) M.Blume, Humboldt-Uni Berlin, 1.1"
  8.  
  9. # include <stdio.h>
  10.  
  11. # include "storext.h"
  12. # include "Boolean.h"
  13. # include "type.h"
  14. # include "identifier.h"
  15. # include "except.h"
  16.  
  17. static
  18. void dump (void *vbool, FILE *file)
  19. {
  20.   putc ((ScmBoolean *)vbool == &ScmTrue
  21.         ? 't'
  22.         : (ScmBoolean *)vbool == &ScmFalse
  23.             ? 'f'
  24.             : (ScmBoolean *)vbool == &ScmEof
  25.                 ? 'e'
  26.                 : 'n',
  27.     file);
  28. }
  29.  
  30. static
  31. void *restore_init (FILE *file)
  32. {
  33.   switch (getc (file)) {
  34.   case 't':
  35.     return &ScmTrue;
  36.   case 'f':
  37.     return &ScmFalse;
  38.   case 'n':
  39.     return &ScmNil;
  40.   case 'e':
  41.     return &ScmEof;
  42.   default: /* including EOF */
  43.     fatal ("bad dump file format (Boolean)");
  44.     break;
  45.   }
  46.   /*NOTREACHED*/
  47. }
  48.  
  49. static
  50. void display (void *vbool, putc_proc pp, void *cd)
  51. {
  52.   if ((ScmBoolean *) vbool == &ScmNil)
  53.     putc_string ("()", pp, cd);
  54.   else if ((ScmBoolean *) vbool == &ScmEof)
  55.     putc_string ("#<End-of-File>", pp, cd);
  56.   else {
  57.     (* pp) ('#', cd);
  58.     (* pp) (((ScmBoolean *) vbool == &ScmTrue) ? 't' : 'f', cd);
  59.   }
  60. }
  61.  
  62. static
  63. struct scheme_od_extension ext = {
  64.   display,
  65.   display,
  66.   NULL,    NULL,        /* Booleans are equal only if they coincide */
  67. };
  68.  
  69. OD_VECTOR (ScmBoolean_od_vector,
  70.   0,            /* these are fixed objects, there can be only one */
  71.   NULL,
  72.   do_nothing_on_subs,
  73.   BOOLEAN_IDENTIFIER,
  74.   dump, restore_init, NULL,
  75.   NULL, NULL, NULL,
  76.   &ext
  77. );
  78.  
  79. ScmBoolean ScmTrue = {
  80.   ScmType (Boolean)
  81. };
  82.  
  83. ScmBoolean ScmFalse = {
  84.   ScmType (Boolean)
  85. };
  86.  
  87. ScmBoolean ScmNil = {
  88.   ScmType (Boolean)
  89. };
  90.  
  91. ScmBoolean ScmEof = {
  92.   ScmType (Boolean)
  93. };
  94.